#include <memory>
#include <functional>
#include <iostream>
#include "ServerCal.hpp"
#include "TcpServer.hpp"

//./Server port
void Usage(std::string cmd)
{
    std::cout << "\n\tUsage:" << cmd << " [port]\n" << std::endl;
}

int main(int argc, char* argv[])
{
    if(argc != 2) {
        Usage(argv[0]);
        exit(0);
    }
    int port = atoi(argv[1]);
    ServerCal cal;
    //使用cal*占位ServerCal::Calculator的第一个参数
    std::unique_ptr<TcpServer> tsv(new TcpServer(port, std::bind(&ServerCal::Calculator, &cal, std::placeholders::_1)));
    tsv->init();
    tsv->start();
    
    // Debug
    // Request rq(15, 12, '+');
    // std::string msg = rq.Serialization();
    // // std::cout << msg << std::endl;
    // std::string package;
    // Encode(msg, &package);
    // std::cout << package << std::endl;

    // std::cout << "Deserialization:" << "\n" << std::endl;
    // std::string msg_2;
    // Decode(package, &msg_2);
    // Request rq_2;
    // rq_2.Deserialization(msg_2);
    // std::cout << rq_2._x << std::endl;
    // std::cout << rq_2._y << std::endl;
    // std::cout << rq_2._op << std::endl;
    return 0;
}